package com.liuyang.second.concurrency.chapter2;

import java.util.stream.IntStream;

public class WaitSet {

    private static final Object LOCK = new Object();

    public static void main(String[] args) throws InterruptedException {
        work();
        Thread.sleep(1_000);
        System.out.println("begin notify");
        synchronized (LOCK){
            LOCK.notify();
        }
//        IntStream.rangeClosed(1, 10)
//                .forEach(i ->
//                        new Thread() {
//                            @Override
//                            public void run() {
//                                synchronized (LOCK) {
//                                    try {
//                                        System.out.println(Thread.currentThread().getName()+" will come to wait set.");
//                                        LOCK.wait();
//                                        System.out.println(Thread.currentThread().getName()+" will leave to wait set.");
//                                    } catch (InterruptedException e) {
//                                        e.printStackTrace();
//                                    }
//                                }
//                            }
//                        }.start());


    }
    public static void work(){
        new Thread(){
            @Override
            public void run() {
                synchronized ((LOCK)){
                    System.out.println("Begin .....");
                    try {
                        System.out.println("Thread will coming");
                        LOCK.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("Thread will out...");

                }
            }
        }.start();

    }
}
